<template>
  <div>
    <el-container>
      <!--    侧边栏  -->
      <el-aside
          :width="asideWidth"
          style="min-height: 100vh; background-color: #001529"
      >
        <div
            style="
            height: 60px;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
          "
        >
          <img
              src="@/assets/logo.png"
              alt=""
              style="width: 40px; height: 40px"
          />
          <span class="logo-title" v-show="!isCollapse">项目管理</span>
        </div>

        <el-menu
            :collapse="isCollapse"
            :collapse-transition="false"
            router
            background-color="#001529"
            text-color="rgba(255, 255, 255, 0.65)"
            active-text-color="#fff"
            style="border: none"
            :default-active="$route.path"
        >
          <el-menu-item index="/home">
            <i class="el-icon-s-home"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-submenu index="info" v-if="user.role === '指导老师' ">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>项目审核</span>
            </template>
            <el-menu-item index="/teacher">项目审阅</el-menu-item>
            <el-menu-item index="/teacher/resourceReview">资源申请</el-menu-item>
          </el-submenu>
          <el-submenu index="info" v-if="user.role ==='管理员'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/user">用户信息</el-menu-item>
            <el-menu-item index="/homegl">首页管理</el-menu-item>
            <el-menu-item index="/class">班级管理</el-menu-item>
            <el-menu-item index="/projectType">项目分类管理</el-menu-item>
            <el-menu-item index="/resourceType">资源分类管理</el-menu-item>
            <el-menu-item index="/mm">校验码管理</el-menu-item>
          </el-submenu>

          <el-submenu index="info"  v-if="user.role === '管理员' ">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>专家管理</span>
            </template>
            <el-menu-item index="/expert">项目评分</el-menu-item>
          </el-submenu>

          <el-submenu index="info"  v-if="user.role === '管理员' ">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>资源管理</span>
            </template>
            <el-menu-item index="/resourcemanage">资源申请</el-menu-item>
          </el-submenu>

          <el-submenu index="info" v-if="user.role ==='评审专家'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>项目评审</span>
            </template>
            <el-menu-item index="/ProjectReview">项目评分</el-menu-item>
          </el-submenu>

          <el-submenu index="info"  v-if="user.role === '学生' ">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>项目管理</span>
            </template>
            <el-menu-item index="/projectApplication">项目申请</el-menu-item>
            <el-menu-item index="/progressUpdate">进度更新</el-menu-item>
            <el-menu-item index="/applicationForResources">资源申请</el-menu-item>
            <el-menu-item index="/record02">项目申请记录</el-menu-item>
            <el-menu-item index="/record">资源申请记录</el-menu-item>
          </el-submenu>
          <el-menu-item index="/reviewResult" v-if="user.role === '学生' " >
            <i class="el-icon-menu"></i>
            <span slot="title">评审结果</span>
          </el-menu-item>
          <el-menu-item index="/progressUpdate" v-if="user.role === '指导老师'|| user.role === '评审专家' " >
            <i class="el-icon-menu"></i>
            <span slot="title">学生项目进度</span>
          </el-menu-item>
          <el-submenu index="info"  v-if="user.role === '管理员' ">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>学生管理</span>
            </template>
            <el-menu-item index="/audit">项目申报</el-menu-item>
          </el-submenu>
          <el-menu-item index="/informationExchange" v-if="user.role === '学生'|| user.role === '管理员'||user.role === '指导老师'|| user.role === '评审专家' " >
            <i class="el-icon-menu"></i>
            <span slot="title">消息交流</span>
          </el-menu-item>
          <el-menu-item index="/feedbackAcceptance" v-if="user.role === '学生'|| user.role === '管理员'||user.role === '指导老师'|| user.role === '评审专家' " >
            <i class="el-icon-menu"></i>
            <span slot="title">文件共享</span>
          </el-menu-item>

<!--          <el-submenu index="info"  v-if="user.role === '学生' ">-->
<!--            <template slot="title">-->
<!--              <i class="el-icon-menu"></i>-->
<!--              <span>智能体</span>-->
<!--            </template>-->
<!--            <el-menu-item index="/deepseek">大模型对话</el-menu-item>-->
<!--            <el-menu-item index="/select">智能生成简历</el-menu-item>-->
<!--          </el-submenu>-->



        </el-menu>
      </el-aside>

      <el-container>
        <!--        头部区域-->
        <el-header>
          <i
              :class="collapseIcon"
              style="font-size: 26px"
              @click="handleCollapse"
          ></i>
          <el-breadcrumb
              separator-class="el-icon-arrow-right"
              style="margin-left: 20px"
          >
            <el-breadcrumb-item :to="{ path: '/' }">主页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: $router.path }">{{ $route.meta.name }}</el-breadcrumb-item>
          </el-breadcrumb>

          <div
              style="
              flex: 1;
              width: 0;
              display: flex;
              align-items: center;
              justify-content: flex-end;
            "
          >
            <i
                class="el-icon-quanping"
                style="font-size: 26px"
                @click="handleFull"
            ></i>
            <el-dropdown placement="bottom">
              <div style="display: flex; align-items: center; cursor: default">
                <img :src="user.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" alt="" style="width: 40px; height: 40px;border-radius: 50%; margin: 0 5px"
                />
                <span>{{ user.name }}</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$router.push('/person')">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/password')">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout" >退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>

        <!--        主体区域-->
        <el-main>
          <router-view @update:user="updateUser"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "HomeView",
  data() {
    return {
      isCollapse: false, // 不收缩
      asideWidth: "200px",
      collapseIcon: "el-icon-s-fold",
      user:JSON.parse(localStorage.getItem('honey-user')||'{}'),
    };
  },
  mounted() {
    //页面加载完成之后触发
    // axios.get('http://localhost:9090/user/selectAll').then(res =>{
    //   console.log(res.data)  //后台返回的数据
    //   this.users=res.data.data
    //   // res.data={   //数据格式
    //   //   code:'200',
    //   //   msg:'请求成功',
    //   //   data:{
    //   //   }
    //   // }
    // })
  },
  methods: {
    updateUser(user){   //获取子组件传过来的数据，更新当前页面的数据
      this.user=JSON.parse(JSON.stringify(user))  //让父级对象跟子级对象毫无关联
    },
    logout() {
      localStorage.removeItem("honey-user"); //清除当前用户的token数据
      this.$router.push("/login");
    },
    handleFull() {
      document.documentElement.requestFullscreen();
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse;
      this.asideWidth = this.isCollapse ? "64px" : "200px";
      this.collapseIcon = this.isCollapse
          ? "el-icon-s-unfold"
          : "el-icon-s-fold";
    },
  },
};
</script>

<style>
.el-menu--inline {
  background-color: #000c17 !important;
}
.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
  padding-left: 49px !important;
}
.el-menu-item:hover,
.el-submenu__title:hover {
  color: #fff !important;
}
.el-submenu__title:hover i {
  color: #fff !important;
}
.el-menu-item:hover i {
  color: #fff !important;
}
.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 5px !important;
  width: calc(100% - 8px);
  margin-left: 4px;
}
.el-menu-item.is-active i,
.el-menu-item.is-active .el-tooltip {
  margin-left: -4px;
}
.el-menu-item {
  height: 40px !important;
  line-height: 40px !important;
}
.el-submenu__title {
  height: 40px !important;
  line-height: 40px !important;
}
.el-submenu .el-menu-item {
  min-width: 0 !important;
}
.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}
/*.el-submenu__icon-arrow {*/
/*  margin-top: -5px;*/
/*}*/

.el-aside {
  transition: width 0.3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
}
.logo-title {
  margin-left: 5px;
  font-size: 20px;
  transition: all 0.3s; /* 0.3s */
}
.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
  display: flex;
  align-items: center;
}
</style>